Avoid narrowing conversion by using operator<< for string output - #29
Conversation
Replace calls to write() with operator<< when writing std::string to streams. std::string::size() returns an unsigned value (size_t), while std::ostream::write() expects a signed std::streamsize, which introduces a narrowing conversion. Using operator<< is simpler, idiomatic, and avoids this type mismatch. It also improves readability without changing behavior.
|
I was completely aware of this. I decided to use I would accept this but can you also check that what I said is true about similarity of the implementations? |
What do you mean? Can you elaborate? |
|
I think my point was this: the intent is to write data to the stream unmodified. I don't want formatting therefore i used |
|
Does it mean you won't accept the change? If so please close the PR. |
Replace calls to write() with operator<< when writing std::string to streams.
std::string::size() returns an unsigned value (size_t), while std::ostream::write() expects a signed std::streamsize, which introduces a narrowing conversion. Using operator<< is simpler, idiomatic, and avoids this type mismatch. It also improves readability without changing behavior.